package game.tileMap.model
{
	import flash.events.Event;
	
	import game.tileMap.model.vo.BossUnit;

	public class GameMapModel extends TileMapModel
	{
		/**
		 *新回合 
		 */		
		public static const NEW_TURN:String = "new_turn";
		/**
		 *下个队伍 
		 */		
		public static const NEXT_TROOP:String = "next_troop";
		/**
		 *战斗开始 
		 */		
		public static const START_FIGHT:String = "start_fight";
		
		
		private static var _instance:GameMapModel
		
		public var troops:Array;
		public var turnSide:int;
		public function GameMapModel()
		{
			super();
		}
		
		public static function getInstance():GameMapModel{
			if (!_instance) {
				
				_instance=new GameMapModel();
				
				
			}
			return _instance;
		}
		
		override protected function init():void{
			super.init();
			
		}
		
		private function sendEvent(name:String):void{
			dispatchEvent(new Event(name));
			
			
		}
		
		override public function setup(mapId:int):void{
			super.setup(mapId);
			var party:Party=new Party();
			party.setup(1);
			troops=[];
			troops.push(party);
			
			party.setCamp(0)
			var troop:Troop=new Troop();
			troop.setCamp(1);
			
			troops.push(troop);
			trace("AAAA"+troops.length);
			for (var j:int;j<troops.length;j++){
				var troop:Troop=troops[j];
				for (var i:int=0;i<troop.members.length;i++){
					
					objArr.push(troop.members[i]);
					
				}
			}
			
			
			
			
		}
		
		
		
		public function get curTroop():Troop{
			
			return troops[turnSide];
		}
		
		
		
		public function nextTroop():void{
			turnSide++;
			
			
			if (turnSide>troops.length-1){
				
				
				//
				trace("全员行动完毕111")
				if (troops[1]!=null){
					sendEvent(START_FIGHT);
					
				}else{
					startNewTurn()
				}
			}else{
				//curTroop.startActs();
				
				//sendEvent(START_FIGHT);
				sendEvent(NEXT_TROOP);
			}
			
		}
		
		public function startNewTurn():void{
			trace("新回合开始！！！")
			turnSide=0;
			for (var j:int=0;j<troops.length;j++){
				var troop:Troop=troops[j];
				for (var i:int=0;i<troop.members.length;i++){
					
					var battler:Battler=troop.members[i];
					battler.isEnd=false;
					
				}
			}
			
			sendEvent(NEW_TURN);
		}
		
		public function checkEndTurn():Boolean{
			if (curTroop.allEnd){
				
				trace(turnSide+"团队全员行动完")
				return true;
				
			}
			return false;
		}
		
		
	}
}